<?php
header("Content-Type: text/html; charset=UTF-8");
$servername = "";
$username = "";
$password = "";
$dbname = "";

$conn = new mysqli($servername, $username, $password, $dbname);

if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
$conn->set_charset("utf8");

$data = file_get_contents("php://input");
$eventinfo = json_decode($data, true);
$title = $eventinfo['title'] ?? '';
$starttime = $eventinfo['starttime'] ?? '';
$endtime = $eventinfo['endtime'] ?? '';
$space = $eventinfo['space'] ?? '';
$type = $eventinfo['type'] ?? '';
$range = $eventinfo['range'] ?? '';

$sql = "INSERT INTO event (title, starttime, endtime, space,type,`range`,status) VALUES ('$title', '$starttime', '$endtime', '$space','$type','$range',0)";

if ($conn->query($sql) === TRUE) {
    echo "New record created successfully";
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>
